/**
  * com.cnhis.his.customer.service.Vaf1Service.java
 */
package com.mbmed.doctor.medadvice.service;

import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.ws.rs.Consumes;
import javax.ws.rs.DELETE;
import javax.ws.rs.Encoded;
import javax.ws.rs.FormParam;
import javax.ws.rs.GET;
import javax.ws.rs.POST;
import javax.ws.rs.Path;
import javax.ws.rs.PathParam;
import javax.ws.rs.Produces;
import javax.ws.rs.QueryParam;
import javax.ws.rs.core.Context;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Request;

import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import com.attilax.web.reqService;
import com.mbmed.doctor.commons.mapper.ModelVo;
import com.mbmed.doctor.commons.utils.DataTransUtils;
import com.mbmed.doctor.commons.utils.DateUtils;
import com.mbmed.doctor.commons.utils.StaticKeys;
import com.mbmed.doctor.commons.utils.ZhongWenUtils;
import com.mbmed.doctor.login.bo.Vae1Bo;
import com.mbmed.doctor.login.mapper.Vae1;
import com.mbmed.doctor.medadvice.bo.Beq1Bo;
import com.mbmed.doctor.medadvice.bo.Vaf2Bo;
import com.mbmed.doctor.medadvice.mapper.Beq1;
import com.mbmed.doctor.medadvice.mapper.Vaf2;
import com.mbmed.doctor.vcf1.bo.Vcf1Bo;

/**
 * @file Vaf1Service.java
 * @author 刘武
 * @version 0.1
 * @todo Vaf1服务操作接口 Copyright(C), 2013-2014 Shenzhen Coordinates Software
 *       Development Co., Ltd. History 1. Date: 2014-10-16 04:24:02 Author: 刘武
 *       Modification: this file was created 2. ...
 */
@Path("/vaf2")
@Component
public class Vaf2Service {

	private static Logger logger = Logger.getLogger(Vaf2.class);

	@Autowired
	private Vaf2Bo vaf2Bo;

	@Autowired
	private Vae1Bo vae1Bo;

	@Autowired
	private Beq1Bo beq1Bo;
	
	@Autowired
	private Vcf1Bo vcf1Bo;

	@Context
	Request request;
	
	
	@Context
	HttpServletRequest request1;
	
	
	
	
	/**http://localhost:1314/hodoctor/vcf1/getBinliFiletype?Type, VAA01, VAA07, ACF01, VAP01, AAG01, BCK01, EmpId, DeptId, DocumentId
	http://localhost:1314/hodoctor/vaf2/getBinliFiletype?Type, VAA01, VAA07, ACF01, VAP01, AAG01, BCK01, EmpId, DeptId, DocumentId
	
	 * 查找所有数据库记录
     * @return type : List 返回查询操作所有符合条件的记录的VO对象集合，操作失败返回null
     */
	@GET   
	@Path("/getBinliFiletype")
	@Produces({MediaType.APPLICATION_XML,MediaType.APPLICATION_JSON})
	 
    public ModelVo getBinliFiletype(@QueryParam("VAF01") java.lang.String VAF01,@QueryParam("Debug_lBCE01") java.lang.Integer Debug_lBCE01) throws Exception{
		ModelVo modelVo = new ModelVo();
		
		 Map<String,Object> paramMap =	reqService.putMapByReqParams("Type, VAA01, VAA07, ACF01, VAP01, AAG01, BCK01, EmpId, DeptId, DocumentId",request1);
        
	//	try{
		
		 
			 
			modelVo.setResult(StaticKeys.SUCCESS);
			List<?> binliFiletype = vcf1Bo.getBinliFiletype(paramMap);
			modelVo.setList(  binliFiletype);
			// modelVo.setRows(binliFiletype);//.subList(0, 2)
		//	modelVo.setMap(map);
			modelVo.setResultMsg("ok");
//		}else{
//			modelVo.setResult(StaticKeys.ERROR);
//			modelVo.setResultMsg("没有查询到医嘱数据");
//		}
        return modelVo;
    }

	/**
	 * 查找所有数据库记录
	 * 
	 * @return type : List 返回查询操作所有符合条件的记录的VO对象集合，操作失败返回null
	 */
	@GET
	@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
	public List<Vaf2> getAll() throws Exception {
		List<Vaf2> list = new ArrayList<Vaf2>();
		return vaf2Bo.getAll();
	}

	/**
	 * 查找符合条件的所有数据库记录
	 * 
	 * @param id
	 *            与数据库中主键对应的值
	 * @return type : 返回查询操作所有符合条件的记录的VO对象，操作失败返回null
	 * @throws Exception
	 */
	@GET
	@Path("{id}")
	@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
	public Vaf2 getVaf1(@PathParam("id") String id) throws Exception {
		Vaf2 vaf2 = null;
		return vaf2Bo.get(id);
	}

	/**
	 * 查询病案手术详情
	 * 
	 * @param id
	 *            与数据库中主键对应的值
	 * @return type : 返回查询操作所有符合条件的记录的VO对象，操作失败返回null
	 * @throws Exception
	 */
	@GET
	@Path("/getmedadvicevaf2byvae01")
	@Produces({ MediaType.APPLICATION_JSON })
	public List<Vaf2> getMedAdviceVaf2ByVae01(@QueryParam("vae01") java.lang.String vae01) throws Exception {
		List<Vaf2> vaf2List = new ArrayList<Vaf2>();
		int ivae01 = Integer.parseInt(vae01);
		vaf2List = vaf2Bo.getMedAdviceVaf2ByVae01(ivae01);
		return vaf2List;
	}

	/**
	 * 向数据库中插入一条记录
	 * 
	 * @param vo
	 *            与数据库中记录对应的值对象
	 * @return type : 返回插入操作是否成功
	 * @throws Exception
	 */
	@POST
	@Produces(MediaType.APPLICATION_JSON)
	@Consumes(MediaType.APPLICATION_FORM_URLENCODED)
	public Vaf2 saveVaf2(@FormParam("vaf01") java.lang.Integer vaf01, @FormParam("vaf01a") java.lang.Integer vaf01a,
			@FormParam("vaf01b") java.lang.Integer vaf01b, @FormParam("vaf04") java.lang.Byte vaf04,
			@FormParam("vaa01") java.lang.Integer vaa01, @FormParam("vaf06") java.lang.Integer vaf06,
			@FormParam("vaf07") java.lang.Integer vaf07, @FormParam("bck01a") java.lang.Integer bck01a,
			@FormParam("rownr") java.lang.Integer rownr, @FormParam("vaf10") java.lang.Byte vaf10,
			@FormParam("vaf11") java.lang.Byte vaf11, @FormParam("bda01") java.lang.String bda01,
			@FormParam("bbx01") java.lang.Integer bbx01, @FormParam("vaf14") java.lang.String vaf14,
			@FormParam("vaf15") java.lang.String vaf15, @FormParam("bby01") java.lang.Integer bby01,
			@FormParam("vaf17") java.lang.Integer vaf17, @FormParam("vaf18") java.math.BigDecimal vaf18,
			@FormParam("vaf19") java.lang.String vaf19, @FormParam("vaf20") java.math.BigDecimal vaf20,
			@FormParam("vaf21") java.math.BigDecimal vaf21, @FormParam("vaf22") java.lang.String vaf22,
			@FormParam("vaf23") java.lang.String vaf23, @FormParam("bck01b") java.lang.Integer bck01b,
			@FormParam("vaf25") java.lang.String vaf25, @FormParam("vaf26") java.lang.String vaf26,
			@FormParam("vaf27") java.lang.Integer vaf27, @FormParam("vaf28") java.lang.Byte vaf28,
			@FormParam("vaf29") java.lang.String vaf29, @FormParam("vaf30") java.lang.String vaf30,
			@FormParam("vaf31") java.lang.Byte vaf31, @FormParam("vaf32") java.lang.Byte vaf32,
			@FormParam("vaf33") java.lang.Byte vaf33, @FormParam("vaf34") java.lang.Byte vaf34,
			@FormParam("vaf35") java.lang.Byte vaf35, @FormParam("vaf36") java.util.Date vaf36,
			@FormParam("vaf37") java.util.Date vaf37, @FormParam("vaf38") java.util.Date vaf38,
			@FormParam("bck01c") java.lang.Integer bck01c, @FormParam("bce02a") java.lang.String bce02a,
			@FormParam("bce03a") java.lang.String bce03a, @FormParam("vaf42") java.util.Date vaf42,
			@FormParam("bce03b") java.lang.String bce03b, @FormParam("bce03c") java.lang.String bce03c,
			@FormParam("vaf45") java.util.Date vaf45, @FormParam("bce03d") java.lang.String bce03d,
			@FormParam("vaf47") java.util.Date vaf47, @FormParam("bce03e") java.lang.String bce03e,
			@FormParam("bce03f") java.lang.String bce03f, @FormParam("vaf50") java.util.Date vaf50,
			@FormParam("vaf51") java.lang.Integer vaf51, @FormParam("vaf52") java.lang.Byte vaf52,
			@FormParam("vaf53") java.lang.Integer vaf53, @FormParam("vaf54") java.lang.Byte vaf54,
			@FormParam("vaf55") java.lang.String vaf55, @FormParam("cbm01") java.lang.Integer cbm01,
			@FormParam("bck01d") java.lang.Integer bck01d, @FormParam("vaf58") java.lang.Byte vaf58,
			@FormParam("vaf59") java.lang.Integer vaf59, @FormParam("vaf60") java.lang.String vaf60,
			@FormParam("vaf61") java.math.BigDecimal vaf61, @FormParam("vaf62") java.math.BigDecimal vaf62,
			@FormParam("bce01a") java.lang.Integer bce01a, @FormParam("bce01b") java.lang.Integer bce01b,
			@FormParam("bce01c") java.lang.Integer bce01c, @FormParam("bce01d") java.lang.Integer bce01d,
			@FormParam("bce01e") java.lang.Integer bce01e, @FormParam("bce01f") java.lang.Integer bce01f,
			@FormParam("bce01g") java.lang.Integer bce01g, @FormParam("bce03g") java.lang.String bce03g,
			@FormParam("vaf71") java.util.Date vaf71, @FormParam("dsk01") java.lang.Integer dsk01,
			@FormParam("vaf01c") java.lang.Integer vaf01c, @FormParam("vaf74") java.util.Date vaf74,
			@FormParam("vaf75") java.lang.Byte vaf75, @FormParam("bce01h") java.lang.Integer bce01h,
			@FormParam("bce03h") java.lang.String bce03h, @FormParam("biw02") java.lang.String biw02,
			@Context HttpServletResponse servletResponse) throws Exception {
		Vaf2 vaf1 = new Vaf2();
		vaf1.setVaf01(vaf01);
		vaf1.setVaf01a(vaf01a);
		vaf1.setVaf01b(vaf01b);
		vaf1.setVaf04(vaf04);
		vaf1.setVaa01(vaa01);
		vaf1.setVaf06(vaf06);
		vaf1.setVaf07(vaf07);
		vaf1.setBck01a(bck01a);
		vaf1.setRownr(rownr);
		vaf1.setVaf10(vaf10);
		vaf1.setVaf11(vaf11);
		vaf1.setBda01(bda01);
		vaf1.setBbx01(bbx01);
		vaf1.setVaf14(vaf14);
		vaf1.setVaf15(vaf15);
		vaf1.setBby01(bby01);
		vaf1.setVaf17(vaf17);
		vaf1.setVaf18(vaf18);
		vaf1.setVaf19(vaf19);
		vaf1.setVaf20(vaf20);
		vaf1.setVaf21(vaf21);
		vaf1.setVaf22(vaf22);
		vaf1.setVaf23(vaf23);
		vaf1.setBck01b(bck01b);
		vaf1.setVaf25(vaf25);
		vaf1.setVaf26(vaf26);
		vaf1.setVaf27(vaf27);
		vaf1.setVaf28(vaf28);
		vaf1.setVaf29(vaf29);
		vaf1.setVaf30(vaf30);
		vaf1.setVaf31(vaf31);
		vaf1.setVaf32(vaf32);
		vaf1.setVaf33(vaf33);
		vaf1.setVaf34(vaf34);
		vaf1.setVaf35(vaf35);
		vaf1.setVaf36(vaf36);
		vaf1.setVaf37(vaf37);
		vaf1.setVaf38(vaf38);
		vaf1.setBck01c(bck01c);
		vaf1.setBce02a(bce02a);
		vaf1.setBce03a(bce03a);
		vaf1.setVaf42(vaf42);
		vaf1.setBce03b(bce03b);
		vaf1.setBce03c(bce03c);
		vaf1.setVaf45(vaf45);
		vaf1.setBce03d(bce03d);
		vaf1.setVaf47(vaf47);
		vaf1.setBce03e(bce03e);
		vaf1.setBce03f(bce03f);
		vaf1.setVaf50(vaf50);
		vaf1.setVaf51(vaf51);
		vaf1.setVaf52(vaf52);
		vaf1.setVaf53(vaf53);
		vaf1.setVaf54(vaf54);
		vaf1.setVaf55(vaf55);
		vaf1.setCbm01(cbm01);
		vaf1.setBck01d(bck01d);
		vaf1.setVaf58(vaf58);
		vaf1.setVaf59(vaf59);
		vaf1.setVaf60(vaf60);
		vaf1.setVaf61(vaf61);
		vaf1.setVaf62(vaf62);
		vaf1.setBce01a(bce01a);
		vaf1.setBce01b(bce01b);
		vaf1.setBce01c(bce01c);
		vaf1.setBce01d(bce01d);
		vaf1.setBce01e(bce01e);
		vaf1.setBce01f(bce01f);
		vaf1.setBce01g(bce01g);
		vaf1.setBce03g(bce03g);
		vaf1.setVaf71(vaf71);
		vaf1.setDsk01(dsk01);
		vaf1.setVaf01c(vaf01c);
		vaf1.setVaf74(vaf74);
		vaf1.setVaf75(vaf75);
		vaf1.setBce01h(bce01h);
		vaf1.setBce03h(bce03h);
		vaf1.setBiw02(biw02);

		return vaf1 = vaf2Bo.save(vaf1);

	}

	/**
	 * 医嘱停止
	 * 
	 * @param vo
	 *            与数据库中记录对应的值对象
	 * @return type : 返回插入操作是否成功
	 * @throws Exception
	 */
	@POST
	@Path("/advicestop")
	@Produces({ MediaType.APPLICATION_JSON })
	public ModelVo adviceStop(@FormParam("vaf01") java.lang.String vaf01, @FormParam("lbce01") java.lang.String lbce01,
			@FormParam("lbce03") java.lang.String lbce03, @FormParam("ltype") java.lang.String ltype,
			@FormParam("vae01") java.lang.String vae01, @FormParam("lucode") java.lang.String lucode,
			@FormParam("luid") java.lang.String luid, @FormParam("lmac") java.lang.String lmac,
			@Context HttpServletResponse servletResponse) {
		ModelVo modelVo = null;
		Map<String, String> paramsMap = new HashMap<String, String>();
		StringBuffer sbuff = new StringBuffer();

		String date = DateUtils.getDateString(new Date());

		sbuff.append("<Root><VAF1>");
		String[] vaf01s = vaf01.split("\\+");
		for (String vaf : vaf01s) {
			sbuff.append("<Ie VAF01=\"");
			sbuff.append(vaf);
			sbuff.append("\" VAF47=\"");
			sbuff.append(date);
			sbuff.append("\"/>");
		}
		sbuff.append("</VAF1></Root>");
		paramsMap.put("rs", "-1");
		paramsMap.put("lxml", sbuff.toString());
		paramsMap.put("lbce01", lbce01);
		paramsMap.put("lbce03", lbce03);
		paramsMap.put("ltype", ltype);
		paramsMap.put("lucode", lucode);
		paramsMap.put("luid", luid);
		paramsMap.put("lmac", lmac);
		try {
			String result = vaf2Bo.execClinicAdviceStop(paramsMap);
			if ("0".equals(result)) {
				modelVo = new ModelVo();
				List<Vaf2> vaf2List = new ArrayList<Vaf2>();
				int ivae01 = Integer.parseInt(vae01);
				vaf2List = vaf2Bo.getMedAdviceVaf2ByVae01(ivae01);
				modelVo.setResult("success");
				modelVo.setList(vaf2List);
				return modelVo;
			} else {
				modelVo = new ModelVo();
				int inResult = Integer.parseInt(result);
				modelVo.setResult("false");
				if (2 == inResult) {
					modelVo.setResultMsg("提交文档错误，医嘱信息为空");
				} else if (3 == inResult) {
					modelVo.setResultMsg("医嘱已经停止，请返回刷新条件重新选择！");
				} else if (inResult > 0) {
					modelVo.setResultMsg("解析XML文档时发生错误!");
				}
				return modelVo;
			}
		} catch (Exception e) {
			e.printStackTrace();
			List<String> list = ZhongWenUtils.charLinked(e.getMessage());
			modelVo = new ModelVo();
			modelVo.setResult("false");
			modelVo.setResultMsg((String) list.get(0) + "," + (String) list.get(1));
			return modelVo;
		}
	}

	/**
	 * 医嘱记录删除
	 * 
	 * @param vo
	 *            与数据库中记录对应的值对象
	 * @return type : 返回插入操作是否成功
	 * @throws Exception
	 */
	@POST
	@Path("/advicesdel")
	@Produces({ MediaType.APPLICATION_JSON })
	public ModelVo adviceDel(@FormParam("vaf01") java.lang.String vaf01, @FormParam("lacf01") java.lang.String lacf01,
			@FormParam("lbce03") java.lang.String lbce03, @FormParam("vae01") java.lang.String vae01,
			@FormParam("lucode") java.lang.String lucode, @FormParam("luid") java.lang.String luid,
			@FormParam("lmac") java.lang.String lmac, @Context HttpServletResponse servletResponse) {
		ModelVo modelVo = null;
		Map<String, Object> paramsMap = new HashMap<String, Object>();
		StringBuffer sbuff = new StringBuffer();
		String[] vaf01s = vaf01.split("\\+");
		int levaf01 = vaf01s.length;
		for (int i = 0; i < levaf01; i++) {
			String vaf01v = vaf01s[i];
			sbuff.append(" select VAF01 = ");
			sbuff.append(vaf01v);
			if (i < (levaf01 - 1)) {
				sbuff.append(" union all ");
			}
		}
		paramsMap.put("rs", "-1");
		paramsMap.put("lxml", sbuff.toString());
		paramsMap.put("lacf01", lacf01);
		paramsMap.put("lbce03", lbce03);
		paramsMap.put("lucode", lucode);
		paramsMap.put("luid", luid);
		paramsMap.put("lmac", lmac);
		try {
			String result = vaf2Bo.execClinicAdvice_Del(paramsMap);

			if ("0".equals(result)) {
				modelVo = new ModelVo();
				List<Vaf2> vaf2List = new ArrayList<Vaf2>();
				int ivae01 = Integer.parseInt(vae01);
				vaf2List = vaf2Bo.getMedAdviceVaf2ByVae01(ivae01);
				modelVo.setResult("success");
				modelVo.setList(vaf2List);
				return modelVo;
			} else {
				modelVo = new ModelVo();
				modelVo.setResult("false");
				modelVo.setResultMsg("操作失败！");
				return modelVo;

			}
		} catch (Exception e) {

			// String str = e.getMessage();
			// StringBuffer sb = new StringBuffer();
			// for (int i = 0; i < str.length(); i++) {
			// if ((str.charAt(i)+"").getBytes().length>1) {
			// sb.append(str.charAt(i));
			// }
			// }
			// System.out.println(sb);

			List<String> list = ZhongWenUtils.charLinked(e.getMessage());
			modelVo = new ModelVo();
			modelVo.setResult("false");
			modelVo.setResultMsg((String) list.get(0) + "," + (String) list.get(1));
		}

		return modelVo;

	}

	/**
	 * 临床药物评价
	 * 
	 * @param vo
	 *            与数据库中记录对应的值对象
	 * @return type : 返回插入操作是否成功
	 * @throws Exception
	 */
	@POST
	@Path("/adviceexecclinicdrugjudge")
	@Produces({ MediaType.APPLICATION_JSON })
	public ModelVo adviceExecClinicDrugJudge(@FormParam("lxml") java.lang.String lxml,
			@FormParam("acf01") java.lang.String acf01, @FormParam("vaa01") java.lang.String vaa01,
			@FormParam("vaa07") java.lang.String vaa07, @FormParam("ltype") java.lang.String ltype,
			@FormParam("lbce01") java.lang.String lbce01, @Context HttpServletResponse servletResponse)
					throws Exception {
		ModelVo modelVo = new ModelVo();
		Map<String, Object> paramsMap = new HashMap<String, Object>();

		paramsMap.put("rs", "");
		paramsMap.put("lxml", lxml);
		paramsMap.put("acf01", acf01);
		paramsMap.put("vaa01", vaa01);
		paramsMap.put("vaa07", vaa07);
		paramsMap.put("ltype", ltype);
		paramsMap.put("lbce01", lbce01);
		String rs = vaf2Bo.execClinicDrugJudge(paramsMap);
		modelVo.setResult(rs);
		return modelVo;

	}

	/**
	 * 临床药物评价
	 * 
	 * @param vo
	 *            与数据库中记录对应的值对象
	 * @return type : 返回插入操作是否成功
	 * @throws Exception
	 */
	@POST
	@Path("/advicejcexecclinicdrugjudge")
	@Produces({ MediaType.APPLICATION_JSON })
	public ModelVo adviceJcExecClinicDrugJudge(@FormParam("lcam1") java.lang.String lcam1,
			@FormParam("lcbm1") java.lang.String lcbm1, @FormParam("lvaf1") java.lang.String lvaf1,
			@FormParam("lvbq") java.lang.String lvbq, @FormParam("acf01") java.lang.String acf01,
			@FormParam("vaa01") java.lang.String vaa01, @FormParam("vaa07") java.lang.String vaa07,
			@FormParam("ltype") java.lang.String ltype, @FormParam("lbce01") java.lang.String lbce01,
			@Context HttpServletResponse servletResponse) throws Exception {
		ModelVo modelVo = new ModelVo();
		Map<String, Object> paramsMap = new HashMap<String, Object>();
		Map<String, Object> paramsMapCam = new HashMap<String, Object>();

		paramsMapCam.put("cam04", lcam1);
		paramsMapCam.put("cam02", "1");
		paramsMapCam.put("cam03", DataTransUtils.parseDateToDate1(new Date()).substring(6));
		paramsMapCam.put("abbrp", lcam1);
		paramsMapCam.put("abbrw ", lcam1);
		paramsMapCam.put("lid", "");

		String lid = vaf2Bo.execClinicCAMInsert(paramsMapCam);
		String lxml = lcbm1 + lvaf1 + getVbqJudge(lcam1, lid) + lvbq;
		paramsMap.put("rs", "");
		paramsMap.put("lxml", lxml);
		paramsMap.put("acf01", acf01);
		paramsMap.put("vaa01", vaa01);
		paramsMap.put("vaa07", vaa07);
		paramsMap.put("ltype", ltype);
		paramsMap.put("lbce01", lbce01);
		String rs = vaf2Bo.execClinicDrugJudge(paramsMap);

		paramsMapCam.clear();

		paramsMapCam.put("lid", lid);
		modelVo.setResult(rs);
		modelVo.setMap(paramsMapCam);
		return modelVo;

	}

	/**
	 * 描述医嘱临床药物评价
	 * 
	 * @param vo
	 *            与数据库中记录对应的值对象
	 * @return type : 返回插入操作是否成功
	 * @throws Exception
	 */
	@POST
	@Path("/advicemsexecclinicdrugjudge")
	@Produces({ MediaType.APPLICATION_JSON })
	public ModelVo adviceMsExecClinicDrugJudge(@FormParam("lcam1") java.lang.String lcam1,
			@FormParam("lcbm1") java.lang.String lcbm1, @FormParam("lvaf1") java.lang.String lvaf1,
			@FormParam("lvao1") java.lang.String lvao1, @FormParam("lvbq") java.lang.String lvbq,
			@FormParam("acf01") java.lang.String acf01, @FormParam("vaa01") java.lang.String vaa01,
			@FormParam("vaa07") java.lang.String vaa07, @FormParam("ltype") java.lang.String ltype,
			@FormParam("lbce01") java.lang.String lbce01, @Context HttpServletResponse servletResponse)
					throws Exception {
		ModelVo modelVo = new ModelVo();
		Map<String, Object> paramsMap = new HashMap<String, Object>();
		Map<String, Object> paramsMapCam = new HashMap<String, Object>();

		paramsMapCam.put("cam04", lcam1);
		paramsMapCam.put("cam02", "1");
		paramsMapCam.put("cam03", DataTransUtils.parseDateToDate1(new Date()).substring(6));
		paramsMapCam.put("abbrp", lcam1);
		paramsMapCam.put("abbrw ", lcam1);
		paramsMapCam.put("lid", "");

		String lid = vaf2Bo.execClinicCAMInsert(paramsMapCam);
		String lxml = lcbm1 + lvao1 + getVaoXmlDugre(lcam1, lid) + lvaf1 + lvbq;
		paramsMap.put("rs", "");
		paramsMap.put("lxml", lxml);
		paramsMap.put("acf01", acf01);
		paramsMap.put("vaa01", vaa01);
		paramsMap.put("vaa07", vaa07);
		paramsMap.put("ltype", ltype);
		paramsMap.put("lbce01", lbce01);
		String rs = vaf2Bo.execClinicDrugJudge(paramsMap);

		paramsMapCam.clear();

		paramsMapCam.put("lid", lid);
		modelVo.setResult(rs);
		modelVo.setMap(paramsMapCam);
		return modelVo;

	}

	/**
	 * 医嘱执行
	 * 
	 * @param vo
	 *            与数据库中记录对应的值对象
	 * @return type : 返回插入操作是否成功
	 * @throws Exception
	 */
	@POST
	@Path("/adviceexecclinicvaf1insert")
	@Produces({ MediaType.APPLICATION_JSON })
	public ModelVo adviceExecClinicVaf1Insert(@FormParam("lVer") java.lang.String lVer,
			@FormParam("lxml") java.lang.String lxml, @FormParam("ltype") java.lang.String ltype,
			@FormParam("lmode") java.lang.String lmode, @FormParam("lcbm01a") java.lang.String lcbm01a,
			@FormParam("lacf01") java.lang.String lacf01, @FormParam("lbck01") java.lang.String lbck01,
			@FormParam("lbce01") java.lang.String lbce01, @FormParam("lbce02") java.lang.String lbce02,
			@FormParam("lbce03") java.lang.String lbce03, @FormParam("luriid") java.lang.String luriid,
			@FormParam("mac") java.lang.String mac, @Context HttpServletResponse servletResponse) {
		ModelVo modelVo = new ModelVo();
		Map<String, Object> paramsMap = new HashMap<String, Object>();

		paramsMap.put("lVer", lVer);
		paramsMap.put("lxml", lxml);
		paramsMap.put("ltype", ltype);
		paramsMap.put("lmode", lmode);
		paramsMap.put("lcbm01a", lcbm01a);
		paramsMap.put("lacf01", lacf01);
		paramsMap.put("lbck01", lbck01);
		paramsMap.put("lbce01", lbce01);
		paramsMap.put("lbce02", lbce02);
		paramsMap.put("lbce03", lbce03);
		paramsMap.put("luriid", luriid);
		paramsMap.put("lmac", mac);
		paramsMap.put("cbmid", "0");
		try {
			vaf2Bo.execClinicVaf1Insert(paramsMap);
		} catch (Exception e) {
			// TODO Auto-generated catch block
			// e.printStackTrace();
			// modelVo.setResult("false");
			// return modelVo;
			List<String> list = ZhongWenUtils.charLinked(e.getMessage());
			modelVo = new ModelVo();
			modelVo.setResult("false");
			modelVo.setResultMsg((String) list.get(0) + "," + (String) list.get(1));
			return modelVo;
		}
		// String cbmid = (String) paramsMap.get("cbmid");
		//
		// try {
		// Thread.sleep(10000);
		// } catch (InterruptedException e) {
		// // TODO Auto-generated catch block
		// e.printStackTrace();
		// }
		//
		modelVo.setResult("success");
		return modelVo;

	}

	/**
	 * 获取临床诊断
	 * 
	 * @param vo
	 *            与数据库中记录对应的值对象
	 * @return type : 返回插入操作是否成功
	 * @throws Exception
	 */
	@POST
	@Path("/advicegetcam")
	@Produces({ MediaType.APPLICATION_JSON })
	public ModelVo adviceGetCam(@FormParam("lcam1") java.lang.String lcam1,
			@Context HttpServletResponse servletResponse) throws Exception {
		ModelVo modelVo = new ModelVo();
		Map<String, Object> paramsMapCam = new HashMap<String, Object>();
		paramsMapCam.put("cam04", lcam1);
		paramsMapCam.put("cam02", "1");
		paramsMapCam.put("cam03", DataTransUtils.parseDateToDate1(new Date()).substring(6));
		paramsMapCam.put("abbrp", lcam1);
		paramsMapCam.put("abbrw ", lcam1);
		paramsMapCam.put("lid", "");
		String lid = vaf2Bo.execClinicCAMInsert(paramsMapCam);
		modelVo.setResult(lid);
		return modelVo;

	}

	/**
	 * 医嘱新开
	 * 
	 * @param vo
	 *            与数据库中记录对应的值对象
	 * @return type : 返回插入操作是否成功
	 * @throws Exception
	 */
	@POST
	@Path("/newadvices")
	@Produces({ MediaType.APPLICATION_JSON })
	public ModelVo newAdvices(@FormParam("bck01") java.lang.String bck01, @FormParam("bce01") java.lang.String bce01,
			@FormParam("vae01") java.lang.String vae01, @Context HttpServletResponse servletResponse) throws Exception {
		ModelVo modelVo = null;

		Map<String, String> paramMap = null;
		// 提取病人状态
		Vae1 statusVae1 = vae1Bo.get(vae01);
		if (statusVae1 != null) {
			java.lang.Byte vae44 = statusVae1.getVae44();
			if (vae44 > 3) {
				// 病人不在院
				modelVo = new ModelVo();
				modelVo.setResultMsg("此病人以下出院医嘱，不能开医嘱！");
				return modelVo;
			}
		}

		// 检查信用额度
		Vae1 creditVae1 = vae1Bo.getLineOfCreditByVae01(vae01);
		if (creditVae1 != null) {
			java.math.BigDecimal fbep06 = creditVae1.getFbep06();
			java.math.BigDecimal fvbm07 = creditVae1.getFvbm07();

			if (fbep06.compareTo(fvbm07) > 0) {
				// 押金余额已低于记账信用额度

				paramMap = new HashMap<String, String>();
				paramMap.put("vae01", vae01);
				paramMap.put("bck01", bck01);
				List<Beq1> beq1list = beq1Bo.getExceptBeq1ByParamMap(paramMap);
				if (beq1list.size() <= 0 || beq1list == null) {
					// 不在记账报警线除外科室
					modelVo = new ModelVo();
					modelVo.setResultMsg("押金余额已低于记账信用额度，不能新开医嘱!");
					return modelVo;

				} else {
					// 在记账报警线除外科室 ，可以开
					modelVo = new ModelVo();
					modelVo = newAddAdvices(bck01, bce01, vae01);
				}
			} else {
				// 可以开！
				modelVo = new ModelVo();
				modelVo = newAddAdvices(bck01, bce01, vae01);
			}
		} else {
			// 没有获取到该病人的记账信息，请联系管理员!
			modelVo = new ModelVo();
			modelVo.setResultMsg("没有获取到该病人的记账信息，请联系管理员!");
			return modelVo;
		}
		return modelVo;
	}

	/**
	 * 医嘱确认
	 * 
	 * @param vo
	 *            与数据库中记录对应的值对象
	 * @return type : 返回插入操作是否成功
	 * @throws Exception
	 */
	@POST
	@Path("/confirmadvices")
	@Produces({ MediaType.APPLICATION_JSON })
	public ModelVo confirmAdvices(@FormParam("vae01") java.lang.String vae01,
			@FormParam("bck01b") java.lang.String bck01b, @FormParam("bck01c") java.lang.String bck01c,
			@FormParam("btn") java.lang.String btn, @FormParam("vaf11") java.lang.String vaf11,
			@FormParam("vaf22") java.lang.String vaf22, @FormParam("vaf23") java.lang.String vaf23,
			@FormParam("vafbck01b") java.lang.String vafbck01b, @FormParam("vaf26") java.lang.String vaf26,
			@FormParam("vaf35") java.lang.String vaf35, @FormParam("vaf36") java.lang.String vaf36,
			@FormParam("vaf37") java.lang.String vaf37, @FormParam("vafbck01c") java.lang.String vafbck01c,
			@FormParam("bce02a") java.lang.String bce02a, @FormParam("bce03a") java.lang.String bce03a,
			@FormParam("vaf53") java.lang.String vaf53, @FormParam("vaf55") java.lang.String vaf55,
			@FormParam("vafbck01d") java.lang.String vafbck01d, @FormParam("vaf58") java.lang.String vaf58,
			@FormParam("vaf59") java.lang.String vaf59, @FormParam("vaf60") java.lang.String vaf60,
			@FormParam("vaf61") java.lang.String vaf61, @FormParam("vaf62") java.lang.String vaf62,
			@FormParam("bda01a") java.lang.String bda01a, @FormParam("bce01a") java.lang.String bce01a,
			@FormParam("biw02") java.lang.String biw02, @Context HttpServletResponse servletResponse) throws Exception {
		ModelVo modelVo = null;

		return modelVo;

	}

	/**
	 * 删除数据库中与传入的值对象对应的记录
	 * 
	 * @param vo
	 *            与数据库中记录对应的值对象
	 * @return type : boolean 返回删除操作是否成功
	 * @throws Exception
	 */
	@DELETE
	@Path("{id}")
	public boolean removeVaf1(@PathParam("id") String id) throws Exception {
		if (id == null)
			return false;
		return vaf2Bo.remove(id);
	}

	public ModelVo newAddAdvices(java.lang.String bck01, java.lang.String bce01, java.lang.String vae01)
			throws Exception {
		ModelVo modelVo = null;
		// 是否发送转科医嘱
		Vaf2 transferVaf2 = vaf2Bo.getTransferVaf2ByVae01(vae01);
		if (null != transferVaf2) {
			modelVo = new ModelVo();
			modelVo.setResultMsg("此病人以下转科医嘱，不能开医嘱!");
			return modelVo;
		} else {
			// 是否下达出院医嘱
			Vaf2 leaveHospitalVaf2 = vaf2Bo.getLeaveHospitalVaf2ByVae01(vae01);
			if (null != leaveHospitalVaf2) {
				modelVo = new ModelVo();
				modelVo.setResultMsg("此病人以下出院医嘱，不能开医嘱!");
				return modelVo;
			}
		}
		modelVo = new ModelVo();
		modelVo.setResult("1");
		return modelVo;
	}

	public String getVbqJudge(String lcam1, String lid) {
		StringBuffer buffer2 = new StringBuffer();
		buffer2.append("<VAO1><Ie");
		buffer2.append(" CBMID=\"" + "-1" + "\"");
		buffer2.append(" VAO06=\"" + "1" + "\"");
		buffer2.append(" VAO07=\"" + "1" + "\"");
		buffer2.append(" VAO10=\"" + "0" + "\"");
		buffer2.append(" VAO11=\"" + "2" + "\"");
		buffer2.append(" BAK01A=\"" + "0" + "\"");
		buffer2.append(" CAM01=\"" + lid + "\"");
		buffer2.append(" VAO15=\"" + lcam1 + "\"");
		buffer2.append("/></VAO1>");
		return buffer2.toString();
	}

	public String getVaoXmlDugre(String lcam1, String lid) {
		StringBuffer buffer = new StringBuffer();
		buffer.append(" CAM01=\"" + lid + "\"");
		buffer.append(" VAO15=\"" + lcam1 + "\"");
		buffer.append(" VAO18=\"" + "0" + "\"");
		buffer.append(" VAO22=\"" + "1" + "\"");
		buffer.append(" IAD03=\"" + "" + "\"");
		buffer.append(" IAA01=\"" + "0" + "\"");
		buffer.append("/></VAO1>");
		return buffer.toString();
	}

	/**
	 * 下达医嘱时，用于显示私人常用项目列表
	 * 
	 * @param vo
	 *            与数据库中记录对应的值对象
	 * @return type : 返回插入操作是否成功
	 * @throws Exception
	 */
	@GET
	@Path("/selcommsprojcet")
	@Produces({ MediaType.APPLICATION_JSON })
	public ModelVo selCommsProjcet(@QueryParam("lBCE01") java.lang.Integer lBCE01,
			@QueryParam("lBCK01") java.lang.Integer lBCK01, @QueryParam("aACF01") java.lang.Integer aACF01)
					throws Exception {
		Map map = new HashMap<>();
		map.put("lBCE01", lBCE01);
		map.put("lBCK01", lBCK01);
		map.put("aACF01", aACF01);
		return vaf2Bo.selCommsProjcet(map);

	}

}
